package com.example.edu.Mapper;

import com.example.edu.Entity.History;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface HistoryMapper {
    @Select("select history_id,history_name from history where history_user = #{id} and type = 0 order by history_id desc limit 10")
    List<History> getHistories(@Param("id") int user_id);

    @Select("select history_id,history_name from history where history_user = #{id} and type = 1 order by history_id desc limit 10")
    List<History> getHistoriesM(@Param("id") int user_id);

    @Update("update history set history_name = #{history.history_name} where history_id = #{history.history_id}")
    void update(@Param("history") History history);

    @Delete("delete from history where history_id = #{history_id}")
    void delete(@Param("history_id") int history_id);

    @Insert("insert into history(history_name, history_user) values (#{history.history_name},#{history.history_user})")
    @Options(useGeneratedKeys = true, keyProperty = "history_id")
    void add(@Param("history") History history);

    @Insert("insert into history(history_name, history_user,type) values (#{history.history_name},#{history.history_user},1)")
    @Options(useGeneratedKeys = true, keyProperty = "history_id")
    void addM(@Param("history") History history);
}
